import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home/index.vue'
import Types from '../views/Types/index.vue'
import Videos from '../views/Video/index.vue'
import Cart from '@/views/Cart/index'
import Cartindex from '@/views/Cart/cartindex'
import Address from '@/views/Cart/address'
import My from '../views/My'
import Myindex from '../views/My/myindex.vue'
import Login from '../views/My/login.vue'
import Register from '../views/My/register.vue'
import store from '@/store/index'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Home
  },
  {
    path: '/types',
    component: Types
  },
  {
    path:'/videos',
    component: Videos
  },
  {
    path: '/cart',
    component: Cart,
    children: [
      {
        path: '/',
        component: Cartindex,
      },
      {
        path: 'address',
        component: Address,
      },]
  },
  {
    path:'/my',
    component: My,
    children:[
      {
        path:'/',
        component:Myindex,
      },
      {
        path:'login',
        component:Login,
      },
      {
        path:'register',
        component:Register,
      }
    ]
  },
]

const router = new VueRouter({
  routes
})

router.afterEach((to, from)=>{
  var active
  if(to.path.startsWith('/my')){
    active = 4
  }
  if(to.path === '/'){
    active = 0
  }else if(to.path === '/types'){
    active = 1
  }else if(to.path === '/videos'){
    active = 2
  }else if(to.path === '/cart'){
    active = 3
  }
  store.commit('changeActive', active)
})

export default router
